package com.shawn.spring.boot.mybatis.mapper;

import com.shawn.spring.boot.mybatis.entity.Menu;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface MenuMapper {

  @Insert(
      "insert into t_menu (`parent_id`, `name`, `url`, `level`, `type`, `order`) values "
          + " (#{menu.parentId}, #{menu.name}, #{menu.url}, #{menu.level}, #{menu.type}, #{menu.order})")
  @Options(useGeneratedKeys = true)
  int insert(@Param("menu") Menu menu);

  int update(@Param("menu") Menu newMenu);

  @Delete("delete from t_menu where menu_id = #{id}")
  int delete(@Param("id") long id);

  @Select("select * from t_menu")
  List<Menu> selectAll();

  @Select("SELECT * FROM t_menu WHERE menu_id = #{id}")
  Menu selectById(@Param("id") Long id);
}
